$(function(){

    $("#list-group").on("click","li",function(){
        $("#list-group .active").removeClass("active");
        $(this).addClass("active");
        var id = $(this).attr("id");
        $("#scj_id").val(id);
    });

    var gn_id = getUrlString("gn_id");
    var gn_mc = decodeURI(getUrlString("gn_mc"));
    $("#gn_id").val(gn_id);
    $("#gn_mc").val(gn_mc);
    $("#list-group li").eq(0).addClass("active");

});


function getUrlString(name) {

    var reg = new RegExp("(^|&)" + name + "=([^&*])(&|$)", "ig");

    var url = window.location.href;

    if (url.indexOf("?") > -1) {

        url = url.substring(url.indexOf("?") + 1, url.length);
        var arr = url.split("&");
        for (var i = 0; i < arr.length; i++) {
            if (name == arr[i].split("=")[0]) {
                return arr[i].split("=")[1]
            }
        }

    }

    return null;

}

function addFolder(){

      var scj_mc = $("#scj_mc").val();
      $.ajax({
            url: "/portal/user/favorite/addFolder.do",
            type: "post",
            data:{
                name:scj_mc
            },
            dataType:"json",
            async:false,
            timeout: sys_timeout,
            error: function (XMLHttpRequest, textStatus) {
                $.messager.alert('请求失败',"系统访问异常："+textStatus);
            },
            success: function (responseText) {
                if(responseText.code==0){
                    var scj_id =responseText.repData.scj_id;
                    $("#scj_id").val(scj_id);
                    $("#list-group .active").removeClass("active");
                    $("#list-group").prepend("<li class='list-group-item title-s active' data='"+scj_id+"' >"+scj_mc+"</li>");
                    $("#list-box").scrollTop(0);
                }else{
                    $.messager.alert('保存失败',"保存失败："+responseText.msg);
                }
            }
      });

      $("#bbxx").hide();

}




function saveFav(){

    var scj_mc = $("#scj_mc").val();
    var scj_id = $("#scj_id").val();
    var gn_id = $("#gn_id").val();

    $.ajax({
        url: "/portal/user/favorite/addGn.do",
        type: "post",
        data:{
            "scj_id":scj_id,
            "gn_id":gn_id
        },
        dataType:"json",
        async:false,
        timeout: sys_timeout,
        error: function (XMLHttpRequest, textStatus) {
            $.messager.alert('请求失败',"系统访问异常："+textStatus);
        },
        success: function (responseText) {
            if(responseText.code==0){
                $.messager.confirm('提示','成功添加功能到收藏夹：'+scj_mc,function(r){
                    if (r){
                        closeWin();
                    }
                });
            }else{
                $.messager.alert('保存失败',"保存失败："+responseText.msg);
            }
        }
    });

}

function closeWin(){
    parent.$("#collectModal").modal('hide');
}